package jp.co.nes.awssupport.test.utility;

import java.util.ArrayList;
import java.util.List;

import jp.co.nes.awssupport.common.bean.BlendedReservedManageBean;

/**
 * 融通リザーブド管理アサーションヘルパーです。
 */
public class AssertBlendedReservedManageHelper extends AbstractAssertHelper<BlendedReservedManageBean> {

    /** 融通リザーブド管理の件数を検索する際に使用するSelect文 */
    private static final String SEL_COUNT = "select count(*) Count from blended_reserved_manage";

    /** 融通リザーブド管理を検索する際に使用するSelect文 */
    private static final String SEL = ""
            + "select UUID,"
            + "       BucketName,"
            + "       ObjectKey,"
            + "       RecordId,"
            + "       PricingPlanId,"
            + "       LinkedAccountId,"
            + "       UsageStartDate,"
            + "       UsageEndDate,"
            + "       UsageQuantity"
            + "  from blended_reserved_manage"
            + " where UUID = ?";

    /**
     * デフォルトコンストラクタです。
     */
    public AssertBlendedReservedManageHelper() {
        super(BlendedReservedManageBean.class);
    }

    /*
     * (非 Javadoc)
     * @see jp.co.nes.awssupport.test.utility.AbstractAssertHelper#getSelectCountQuery()
     */
    @Override
    protected String getSelectCountQuery() {
        return SEL_COUNT;
    }

    /*
     * (非 Javadoc)
     * @see jp.co.nes.awssupport.test.utility.AbstractAssertHelper#getSelectBeanQuery()
     */
    @Override
    protected String getSelectBeanQuery() {
        return SEL;
    }

    /*
     * (非 Javadoc)
     * @see jp.co.nes.awssupport.test.utility.AbstractAssertHelper#toConditionList(jp.co.nes.awssupport.common.bean.BaseBean)
     */
    @Override
    protected List<Object> toConditionList(BlendedReservedManageBean bean) {
        List<Object> conditionList = new ArrayList<>();
        conditionList.add(bean.getUuid());
        return conditionList;
    }

    /*
     * (非 Javadoc)
     * @see jp.co.nes.awssupport.test.utility.AbstractAssertHelper#isMatch(jp.co.nes.awssupport.common.bean.BaseBean, jp.co.nes.awssupport.common.bean.BaseBean)
     */
    @Override
    protected boolean isMatch(BlendedReservedManageBean actualBean, BlendedReservedManageBean expectedBean) {
        if (actualBean == null) {
            if (expectedBean == null) {
                return true;
            } else {
                return false;
            }
        } else {
            if (expectedBean == null) {
                return false;
            }
        }

        StringBuilder actual = new StringBuilder();
        actual.append(actualBean.getUuid());

        StringBuilder expected = new StringBuilder();
        expected.append(expectedBean.getUuid());

        if (actual.toString().equals(expected.toString())) {
            return true;
        }
        return false;
    }
}
